package com.cxxx.guns.modular.backend.common.factory;

//
//                       _oo0oo_
//                      o8888888o
//                      88" . "88
//                      (| -_- |)
//                      0\  =  /0
//                    ___/`---'\___
//                  .' \\|     |// '.
//                 / \\|||  :  |||// \
//                / _||||| -:- |||||- \
//               |   | \\\  -  /// |   |
//               | \_|  ''\---/''  |_/ |
//               \  .-\__  '-'  ___/-. /
//             ___'. .'  /--.--\  `. .'___
//          ."" '<  `.___\_<|>_/___.' >' "".
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//         \  \ `_.   \_ __\ /__ _/   .-` /  /
//     =====`-.____`.___ \_____/___.-`___.-'=====
//                       `=---='
//
//
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//               佛祖保佑         永无BUG
//

import com.cxxx.guns.core.util.SpringContextHolder;
import com.cxxx.guns.core.util.ToolUtil;
import com.cxxx.guns.modular.backend.common.Const;
import com.cxxx.guns.modular.backend.dao.TeachersClassMapper;
import com.cxxx.guns.modular.backend.model.Model;
import com.cxxx.guns.modular.backend.model.TeachersClass;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * By CCZhang
 * Time: 2018/9/14:13:23
 */
@Component
@DependsOn("springContextHolder")
public class BackendFactory {
    private TeachersClassMapper teachersClassMapper = SpringContextHolder.getBean(TeachersClassMapper.class);

    public static BackendFactory me() {
        return SpringContextHolder.getBean("backendFactory");
    }

    /**
     * 教研分类转换
     *
     * @param teachersClassId
     * @return
     */
    public String getTeachersClassName(Integer teachersClassId) {
        TeachersClass teachersClass = teachersClassMapper.selectById(teachersClassId);
        if (ToolUtil.isNotEmpty(teachersClass)) {
            return teachersClass.getName();
        }
        return "--";
    }

    /**
     * 模块分类转换
     *
     * @param model
     * @return
     */
    public String getModelName(Integer model) {
        List<Model> list = Const.getModelList();
        for (Model m : list) {
            if (ToolUtil.equals(m.getId(), model)) {
                return m.getName();
            }
        }
        return "--";
    }


    /**
     * 状态转换
     *
     * @param status
     * @return
     */
    public String getStatusName(Integer status) {
        for (Const.JiaXiaoStatusEnum jiaXiaoStatusEnum : Const.JiaXiaoStatusEnum.values()) {
            if (ToolUtil.equals(status, jiaXiaoStatusEnum.getCode())) {
                return jiaXiaoStatusEnum.getValue();
            }
        }
        return "--";
    }

    /**
     * getCategoryName
     * @param category
     * @return
     */
    public String getCategoryName(Integer category) {
        for (Const.ImageCategoryEnum imageCategoryEnum : Const.ImageCategoryEnum.values()) {
            if (ToolUtil.equals(category, imageCategoryEnum.getCode())) {
                return imageCategoryEnum.getValue();
            }
        }
        return "--";
    }
}
